<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区 -->
    <el-card>
      <!--搜索区 -->
      <el-row :gutter="40">
        <el-col :span="10">
          <el-input placeholder="请输入内容">
            <el-button
              slot="append"
              icon="el-icon-search"
              clearable
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格区 -->
      <el-table :data="orderData" style="width: 100%" border>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-button type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-button
            >
            <el-button type="warning" else>未付款</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editOrder"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showExpress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!--分页区  -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>

      <!-- 编辑订单 对话框 -->
      <el-dialog title="编辑订单" :visible.sync="dialogVisible" width="50%">
        <el-form
          :model="aditForm"
          :rules="aditFormRules"
          ref="aditFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-input v-model="aditForm.address1"></el-input>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="aditForm.address2"></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <!-- 物流信息 对话框 -->
      <el-dialog title="编辑订单" :visible.sync="ShowdialogVisible" width="50%">
        <!--时间线显示 物流信息 -->
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in expressInfo"
            :key="index"
            :timestamp="item.time"
          >
            {{item.content }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      orderData: [{ total: 1 }],
      total: 0,
      // 对话框是否可见
      dialogVisible: false,
      // 编辑订单数据
      aditForm: {
        address1: [],
        address2: '',
      },
      // 表单验证规则
      aditFormRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      // 物流信息
      expressInfo: [],
      // 物流信息对话框
      ShowdialogVisible: false,
    }
  },
  created() {
    //   this.getOrderData()
  },
  methods: {
    // 请求订单数据
    async GetOrderData() {
      const { data: res } = await this.$http.get('order', {
        params: this.queryInfo,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单数据失败')
      }
      // this.$message.success('获取订单数据成功')
      this.orderData = res.data.goods
      this.total = res.data.total
    },
    // pagesize发生变化
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.GetOrderData()
    },
    // pagenum 发生变化
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.GetOrderData()
    },
    // 编辑订单
    editOrder() {
      this.dialogVisible = true
    },
    // 物流信息
    showExpress() {
      this.ShowdialogVisible = true
    },
  },
}
</script>

<style scoped>
.el-table {
  margin: 15px 0;
}
</style>
